/*
 * Created on 09.11.2006 by leck
 *
 */
package de.devisnik.shifting.impl;

import java.util.ArrayList;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;


public class PieceShifter extends Shifter {
    
    private static class ControlShiftableAdapter implements IShiftable {

        private final Control itsLabel;

        public ControlShiftableAdapter(Control label) {
            itsLabel = label;
            
        }
        
        public Point getPosition() {
            return itsLabel.getLocation();
        }

        public boolean isDisposed() {
            return itsLabel.isDisposed();
        }

        public void setPosition(int x, int y) {
            itsLabel.setLocation(x, y);
        }

		public Point getSize() {
			return itsLabel.getSize();
		}
        
    }

    private final Display itsDisplay;
	private final int itsShiftingDelay;
     
    public PieceShifter(Control label, int steps, int totalX, int totalY, int shiftingDelay, ArrayList/*<IPuzzleCanvasListener>*/ listeners) {
        super(new ControlShiftableAdapter(label), steps, totalX, totalY, listeners);
		this.itsShiftingDelay = shiftingDelay;
        itsDisplay = label.getDisplay();
    }
        
    protected void schedule(Runnable runnable) {
        itsDisplay.timerExec(itsShiftingDelay, runnable);
    }
    
}
